package cn.xscrum.vtsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspPost;
import cn.xscrum.vtsp.service.IVtspPostService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 岗位信息Controller
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/post")
public class VtspPostController extends BaseController
{
    private String prefix = "vtsp/post";

    @Autowired
    private IVtspPostService vtspPostService;

    @RequiresPermissions("vtsp:post:view")
    @GetMapping()
    public String post()
    {
        return prefix + "/post";
    }

    /**
	 * 查询岗位信息列表
     */
    @RequiresPermissions("vtsp:post:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspPost vtspPost)
    {
        startPage();
        List<VtspPost> list = vtspPostService.selectVtspPostList(vtspPost);
        return getDataTable(list);
    }

    /**
	 * 导出岗位信息列表
     */
    @RequiresPermissions("vtsp:post:export")
    @Log(title = "岗位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspPost vtspPost)
    {
        List<VtspPost> list = vtspPostService.selectVtspPostList(vtspPost);
        ExcelUtil<VtspPost> util = new ExcelUtil<VtspPost>(VtspPost.class);
        return util.exportExcel(list, "post");
    }

    /**
	 * 新增岗位信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存岗位信息
     */
    @RequiresPermissions("vtsp:post:add")
    @Log(title = "岗位信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspPost vtspPost)
    {
        return toAjax(vtspPostService.insertVtspPost(vtspPost));
    }

    /**
	 * 修改岗位信息
     */
    @GetMapping("/edit/{postId}")
    public String edit(@PathVariable("postId") Long postId, ModelMap mmap)
    {
        VtspPost vtspPost = vtspPostService.selectVtspPostById(postId);
        mmap.put("vtspPost", vtspPost);
        return prefix + "/edit";
    }

    /**
	 * 修改保存岗位信息
     */
    @RequiresPermissions("vtsp:post:edit")
    @Log(title = "岗位信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspPost vtspPost)
    {
        return toAjax(vtspPostService.updateVtspPost(vtspPost));
    }

    /**
	 * 删除岗位信息
     */
    @RequiresPermissions("vtsp:post:remove")
    @Log(title = "岗位信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vtspPostService.deleteVtspPostByIds(ids));
    }
}
